home *** CD-ROM | disk | FTP | other *** search
- Path: news.kei.com!ub!newserve!rebecca!rpi!not-for-mail
- From: floydb1@lib105.its.rpi.edu (Barry B Floyd)
- Newsgroups: comp.lang.c++
- Subject: Re: cin.flush( )???
- Date: 29 Jan 1996 14:41:36 -0500
- Organization: Rensselaer Polytechnic Institute, Troy, NY.
- Message-ID: <4ej7tg$fe2@lib105.its.rpi.edu>
- References: <00001a81+0000956f@msn.com>
- NNTP-Posting-Host: lib105.its.rpi.edu
- X-newsreader: xrn 7.04-beta-11
-
-
- In article <00001a81+0000956f@msn.com>, RMarlowe@msn.com (Roger Marlowe) writes:
- |> Does anyone know how to clear (flush) the cin stream?
- |> I have a persistant problem with unwanted '\n's hanging around in there.
- |> flush(รก) seems to work well with cout but where is it's counterpart for cin?
-
- ...ignore ( len, delim ) ;
-
- I have had varying degrees of success with this. I believe my lack
- of success is due to my lack of understanding the underlying buf
- environment. For example, ...ignore ( 1024, EOF ) in my mind should
- do nothing if the cin buffer is empty - but in practice ( GNU g++ )
- it seems to ignore the next time I use 'cin >> variable'. Checking
- for EOF before ignore doesn't always seem to work either - limited
- tests seem to indicate that the variable type matters.
-
- For now I have ignored my lack of understanding and implemented
- something that works in a limited context. The following works as
- expected (if there is ZERO or ONE extra '\n' in cin's buf):
-
- while ( TRUE )
- {
- String name = STR_EOS ;
-
- cout << " Name: " ;
-
- if ( cin.peek () != EOF )
- cin.ignore ( 80, '\n' ) ;
-
- cin >> name ;
- }
-
-
- If anyone has some diverse source code examples of cin usage please
- post references to the group.
-
- barry
- --
- +--------------------------------------------------------------------+
- | Barry B. Floyd \\\ floydb1@rpi.edu |
- | RPI Alum. '84 '87 '88 \\\ |
- +--------------------------------------------------------------------+
-